/* ESPRESSIF MIT License
 * 
 * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
 * 
 * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
 * it is free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include "app_camera.h"

static const char *TAG = "app_camera";

#if 0

void app_camera_init()

{

    camera_config_t config;

    config.ledc_channel = LEDC_CHANNEL_0;

    config.ledc_timer = LEDC_TIMER_0;

    config.pin_d0 = Y2_GPIO_NUM;

    config.pin_d1 = Y3_GPIO_NUM;

    config.pin_d2 = Y4_GPIO_NUM;

    config.pin_d3 = Y5_GPIO_NUM;

    config.pin_d4 = Y6_GPIO_NUM;

    config.pin_d5 = Y7_GPIO_NUM;

    config.pin_d6 = Y8_GPIO_NUM;

    config.pin_d7 = Y9_GPIO_NUM;

    config.pin_xclk = XCLK_GPIO_NUM;

    config.pin_pclk = PCLK_GPIO_NUM;

    config.pin_vsync = VSYNC_GPIO_NUM;

    config.pin_href = HREF_GPIO_NUM;

    config.pin_sscb_sda = SIOD_GPIO_NUM;

    config.pin_sscb_scl = SIOC_GPIO_NUM;

    config.pin_pwdn = PWDN_GPIO_NUM;

    config.pin_reset = -1;//RESET_GPIO_NUM;

    config.xclk_freq_hz = XCLK_FREQ;

    config.pixel_format = CAMERA_PIXEL_FORMAT;

    config.frame_size = CAMERA_FRAME_SIZE;

    config.jpeg_quality = 10;

    config.fb_count = 1;



    // camera init

    esp_err_t err = esp_camera_init(&config);

    if (err != ESP_OK) {

        ESP_LOGE(TAG, "Camera init failed with error 0x%x", err);

        return;

    }

}

#else





#define CAM_PIN_RESET   15 //software reset will be performed

#define CAM_PIN_XCLK    27

#define CAM_PIN_SIOC    23



#define CAM_PIN_D7      19

#define CAM_PIN_D6      36

#define CAM_PIN_D5      18

#define CAM_PIN_D4      39

#define CAM_PIN_D3      5

#define CAM_PIN_D2      34

#define CAM_PIN_D1      35

#define CAM_PIN_D0      32



#define CAM_PIN_HREF    26

#define CAM_PIN_PCLK    21



#define CAM_XCLK_FREQ   10000000

#define CAMERA_LED_GPIO 14



#define CAM_PIN_SIOD    22

#define CAM_PIN_VSYNC   25

void app_camera_init()

{

    camera_config_t config;

    config.ledc_channel = LEDC_CHANNEL_0;

    config.ledc_timer = LEDC_TIMER_0;

    config.pin_d0 = CAM_PIN_D0;

    config.pin_d1 = CAM_PIN_D1;

    config.pin_d2 = CAM_PIN_D2;

    config.pin_d3 = CAM_PIN_D3;

    config.pin_d4 = CAM_PIN_D4;

    config.pin_d5 = CAM_PIN_D5;

    config.pin_d6 = CAM_PIN_D6;

    config.pin_d7 = CAM_PIN_D7;

    config.pin_xclk = CAM_PIN_XCLK;

    config.pin_pclk = CAM_PIN_PCLK;

    config.pin_vsync = CAM_PIN_VSYNC;

    config.pin_href = CAM_PIN_HREF;

    config.pin_sscb_sda = CAM_PIN_SIOD;

    config.pin_sscb_scl = CAM_PIN_SIOC;

    config.pin_pwdn = PWDN_GPIO_NUM;

    config.pin_reset = CAM_PIN_RESET;//RESET_GPIO_NUM;

    config.xclk_freq_hz = CAM_XCLK_FREQ;

    config.pixel_format = PIXFORMAT_JPEG;

    config.frame_size = FRAMESIZE_QVGA;

    config.jpeg_quality = 15;

    config.fb_count = 1;



    // camera init

    esp_err_t err = esp_camera_init(&config);

    if (err != ESP_OK) {

        ESP_LOGE(TAG, "Camera init failed with error 0x%x", err);

        return;

    }

}

#endif
